{% import 'macros.html' as macros %}
<div class="gcb-nav left-menu" id="gcb-nav-y" role="navigation">
  <ul>
    {{course_info.unit.after_leftnav_begins | safe}}

    {% if not course_info.unit.show_unit_links_in_leftnav %}
        {% for unit, lessons, lesson_progress in course_outline %}
            {% if unit_id == unit.unit_id %}
                {% for lesson in lessons %}
                    {{ macros.render_lesson_title(
                         page_type, unit, lesson, lesson_id, lesson_progress,
                         is_progress_recorded, is_course_admin) }}
                {% endfor %}
            {% endif %}
        {% endfor %}
    {% else %}
        {% for unit, lessons, lesson_progress in course_outline %}
            {{ macros.render_unit_title(
                 unit, unit_progress, is_progress_recorded, transient_student,
                 is_course_admin, unit.type != 'U',
                 'gcb-unit-title expanded'
                     if unit_id == unit.unit_id else 'gcb-unit-title'
                         if lessons else 'gcb-unit-title expanded leaf') }}
            <div id="gcb-lesson-container"
                {% if unit_id == unit.unit_id %}
                    class="gcb-lesson-container expanded"
                {% else %}
                    class="gcb-lesson-container"
                {% endif%}>
            {% for lesson in lessons %}
                {{ macros.render_lesson_title(
                     page_type, unit, lesson, lesson_id, lesson_progress,
                     is_progress_recorded, is_course_admin) }}
            {% endfor %}
            </div>
        {% endfor %}
        <script>
            $('li.gcb-unit-title').click(function() {
                if ($(this).hasClass('leaf')) {
                    return;
                }
                if ($(this).hasClass('expanded')) {
                    $(this).removeClass('expanded');
                    $(this).next().removeClass('expanded');
                } else {
                    $(this).addClass('expanded');
                    $(this).next().addClass('expanded');
                }
            });
        </script>
    {% endif %}

    {{course_info.unit.before_leftnav_ends | safe}}
  </ul>
</div>
